package main;

/*
 * Programming graphical user interfaces
 * Example: DrawImage.java
 * Jarkko Leponiemi 2003
 */

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.image.ImageObserver;

import javax.swing.JPanel;

public class DrawImage extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Image img = null;
	private MyJFrame frame;

	public void setContent(String file) {
		Toolkit toolkit = getToolkit();
		img = toolkit.createImage(file);
	}

	public void setData(byte[] buffer, int len) {
		Toolkit toolkit = getToolkit();
		img = toolkit.createImage(buffer, 0, len);
	}

	public DrawImage() {
	}

	public void paint(Graphics g) {
		Dimension d = getSize();
		Insets i = getInsets();
		g.drawImage(img, i.left, i.top, d.width - i.left - i.right, d.height - i.top - i.bottom, this);
	}

	public void setFrame(MyJFrame myJFrame) {
		frame = myJFrame;
	}
}
